package com.bw.service.Handler;

import com.alibaba.fastjson2.JSON;
import com.bw.service.IMServer;
import com.bw.service.domain.Command;
import com.bw.service.domain.Result;
import io.netty.channel.ChannelHandlerContext;

public class DownLineHandler {
    public static void execute(ChannelHandlerContext channelHandlerContext, Command command) {
        if (IMServer.USERS.containsKey(command.getNickname())) {
            IMServer.USERS.remove(command.getNickname());
            channelHandlerContext.channel().writeAndFlush(Result.success("下线成功"));
            //返回群聊的人
            channelHandlerContext.channel().writeAndFlush(Result.success(JSON.toJSONString(IMServer.USERS.keySet())));
        } else {
            channelHandlerContext.channel().writeAndFlush(Result.fail("请先上线"));
        }
    }
}
